<?php
 /**
  * hjl:前台微商城视频详情页
  */

define('IN_ECS', true);
define('ECS_ADMIN', true);

require(dirname(__FILE__) . '/includes/init.php');
$vedio_id=$_REQUEST['id'];
$sql="select course_id from {$GLOBALS['ecs']->table('course_vedio')} where vedio_id='$vedio_id'";
$course_id = $db->getOne($sql);  //视频隶属的课程ID

$sql = "select * from {$GLOBALS['ecs']->table('course')}";
$all_course=$GLOBALS['db']->getAll($sql);

$lev1_course_id = get_top_lev($all_course,$course_id);  //一级课程的ID

//判断是不是有效会员(用户有没有购买过这个课程并且这个课程没有过期)
if ($_SESSION['user_id'] > 0)
{
	$smarty->assign('user_name', $_SESSION['user_name']);

}


$sql="select * from {$GLOBALS['ecs']->table('course_vedio')} where vedio_id='$vedio_id'";

$vedio_info=$db->getRow($sql);
//print_r($vedio_info);exit;
$smarty->assign('vedio_info',$vedio_info);

$xg_vedios=get_xg_vedio($vedio_id); //相关商品
//print_r($xg_vedios);exit;
$smarty->assign('xg_vedios',$xg_vedios);

if(check_valid_member($_SESSION['user_id'],$lev1_course_id)){

       //有效会员
       $smarty->display('wx_vedio_y.dwt');
        
}else{

      //非效会员
      $smarty->display('wx_vedio_n.dwt');   
}




/*hjl: 取出相关商品 */
function get_xg_vedio($vedio_id){
    $sql="select course_id from {$GLOBALS['ecs']->table('course_vedio')} where vedio_id='$vedio_id'";
     $course_id=$GLOBALS['db']->getOne($sql); //课程ID
     $sql="select * from {$GLOBALS['ecs']->table('course_vedio')} where course_id='$course_id' and is_show=1 and vedio_id!='$vedio_id'";
     $xg_vedios=$GLOBALS['db']->getAll($sql);
     foreach($xg_vedios as $k=>$v){
     	 $xg_vedios[$k]['description']=sub_str($v['description'], 16, true);
     }
     return $xg_vedios;exit;

}


//排序函数
function sort_cat($cat,$parent_id,$level=0,&$arr=array()){

   //static $arr=array();
   foreach($cat as $k=>$v){
     if($v['parent_id']==$parent_id){
        $v['level']=$level;
        $arr[]=$v;
        unset($cat[$k]);
        sort_cat($cat,$v['course_id'],$level+1,$arr);
     }
   }
  return $arr;
  //print_r($arr);exit;
}